﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NHibernate.Criterion;

namespace TVN.ShopMan.ActiveImpl.Repositories
{
    using TVN.ShopMan.ActiveModels;

    public class GenericDataRepository : RepositoryBase<GenericData>
    {
        /// <summary>
        /// Get object by its id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override GenericData GetById(object id)
        {
            return GenericData.Find(id);
        }

        public override IList<GenericData> FindBy(IDictionary propertyNameValues)
        {
            GenericData[] resultItems = null;

            if ((propertyNameValues == null) || (propertyNameValues.Count == 0))
            {
                resultItems = GenericData.FindAll();
            }
            else
            {
                DetachedCriteria criteria = DetachedCriteria.For<GenericData>().Add(Expression.AllEq(propertyNameValues));
                resultItems = GenericData.FindAll(criteria);
            }

            return new List<GenericData>(resultItems);
        }
    }
}
